# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : time_tools.py
# Time       ：2024/8/14 10:15
# Author     ：Yakult
# Email      ：soyakult@163.com
# Description：
"""
import copy
import datetime
import random
from typing import Iterable, List


def get_random_date_list(
        begin_date: str or datetime.datetime.date,
        end_date: str or datetime.datetime.date,
        random_days: Iterable,
) -> List[List[str]]:
    """
    依据random_days将起止时间拆分为n组起止时间

    Args:
        begin_date: 时间起
        end_date: 时间止
        random_range: 随机天数范围

    Returns:

    """
    res = []

    if isinstance(begin_date, str):
        begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d").date()
    if isinstance(end_date, str):
        end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d").date()
    # 中间时间
    middle_date = copy.deepcopy(begin_date)
    while middle_date < end_date:
        date_tuple = [str(middle_date)]
        n = random.randint(*random_days)
        days = datetime.timedelta(days=n)
        middle_date = middle_date + days
        if middle_date > end_date:
            middle_date = end_date
        date_tuple.append(str(middle_date))
        res.append(date_tuple)

    return res
